package com.api.controller;

import com.api.base.service.UserService;
import com.api.common.mybatis.ResultMap;
import com.api.core.annotation.PowerEnable;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.tournament.service.TournamentService;
import com.api.user.service.CommodityOrderService;
import com.api.user.service.CompanionOrderService;
import com.api.user.service.RechargeOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@PowerEnable(name = "DataAnalysis",url = "/")
@Api(value = "DataAnalysis", tags = {"DataAnalysis"})
@RestController
public class DataAnalysis {


    @Resource
    private CommodityOrderService commodityOrderService;
    @Resource
    private RechargeOrderService rechargeOrderService;
    @Resource
    private CompanionOrderService companionOrderService;
    @Resource
    private TournamentService tournamentService;
    @Resource
    private UserService userService;

    @ApiOperation(value = "订单数据年月", tags = {"DataAnalysis"}, notes = "订单数据年月")
    @PostMapping(value="/order/analysis",name="订单数据年月")
    public Result order(@RequestParam Integer type) {
        Map<String,Object> ores = new HashMap<>();
        List<ResultMap<String,Object>> commodity =   commodityOrderService.analysis(type);
        List<ResultMap<String,Object>> recharge =   rechargeOrderService.analysis(type);
        List<ResultMap<String,Object>> companion =   companionOrderService.analysis(type);

        List<ResultMap<String,Object>> dayCommodity =   commodityOrderService.dayAnalysis();
        List<ResultMap<String,Object>> dayRecharge =   rechargeOrderService.dayAnalysis();
        List<ResultMap<String,Object>> dayCompanion =   companionOrderService.dayAnalysis();
        ores.put("commodity",commodity);
        ores.put("recharge",recharge);
        ores.put("companion",companion);
        ores.put("dayCommodity",dayCommodity);
        ores.put("dayRecharge",dayRecharge);
        ores.put("dayCompanion",dayCompanion);
        return ResultGenerator.genSuccessResult(ores);
    }


    @ApiOperation(value = "赛事统计", tags = {"DataAnalysis"}, notes = "赛事统计")
    @PostMapping(value="/tournament/analysis",name="赛事统计")
    public Result tournament() {
        List<Map<String,Object>> res = tournamentService.analysis();
        return ResultGenerator.genSuccessResult(res);
    }

    @ApiOperation(value = "用户统计", tags = {"DataAnalysis"}, notes = "用户统计")
    @PostMapping(value="/user/analysis",name="用户统计")
    public Result user() {
        Map<String,Object> res = new HashMap<>();
        List<Map<String,Object>> hourUser = userService.registerAnalysis();
        List<ResultMap<String,Object>> hourRecharge =   rechargeOrderService.hourAnalysis();
        res.put("hourUser",hourUser);
        res.put("hourRecharge",hourRecharge);
        return ResultGenerator.genSuccessResult(res);
    }

}
